package 线程第一天.卖票案例同步代码款;


public class MyRunnable implements Runnable{
    private int ticketCount = 30;
    private Object lock = new Object();
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(300);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lock){
                if (ticketCount <= 0){
                    break;
                }else {
                    System.out.println(Thread.currentThread().getName()+"正在卖第"+ticketCount+"张票");
                    ticketCount--;
                }
            }
        }
    }
}
